<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/5/31
  Time: 20:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/common.jsp" %>
<html>
<head>
    <title>Title</title>

    <script>
        $(function () {
            $('#table').bootstrapTable({
                url: '<%=path%>/route/selectserver',
                method: 'post',                      //请求方式（*）
                contentType: "application/x-www-form-urlencoded",
                toolbar: '#for_div',              //工具按钮用哪个容器
                striped: true,                     //是否显示行间隔色
                cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,//是否显示分页（*）
                sortOrder: "desc",//排序方式
                sortName: "rid",//排序字段
                sidePagination: "server",//分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,//初始化加载第一页，默认第一页,并记录
                pageSize: 3,//每页的记录行数（*）
                pageList: [1, 3, 5],//可供选择的每页的行数（*）
                // search: true,//是否显示表格搜索
                // strictSearch: true,//严格搜索
                showColumns: true,//是否显示所有的列（选择显示的列）
                showRefresh: true,//是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
                // cardView: true,                    //是否显示详细视图
                detailView: true,                  //是否显示父子表
                //列
                queryParams: function (params) {
                    var temp = {
                        pageSize: params.limit,
                        pageNumber: (params.offset / params.limit) + 1,
                        //天条件查询
                        rname: $("#rname").val(),
                        rflag: $("#rflag").val(),
                        roomid: $("[name=roomid]").val()
                    }
                    return temp;
                },
                columns: [{
                    checkbox: true,
                    visible: true                  //是否显示复选框
                }, {
                    field: 'rid',
                    title: '旅游线路ID'
                }, {
                    field: 'rname',
                    title: '旅游地风景'
                },
                    {
                        field: 'price',
                        title: '旅游地价格',
                    },
                    {
                        field: 'routeintroduce',
                        title: '旅游地简介'
                    },
                    {
                        field: 'rflag',
                        title: '是否上下架',
                        formatter(value, row, index) {
                            if (value == 1) {
                                return "上架"
                            }
                            if (value == 2) {
                                return "下架"
                            }
                        }
                    },
                    {
                        field: 'rdate',
                        title: '上架时间'
                    }, {
                        field: 'isthemetour',
                        title: '是否是旅游主题',
                        formatter(value, row, index) {
                            if (value == 0) {
                                return "是";
                            }
                            if (value == 1) {
                                return "不是";
                            }
                        }

                    },
                    {
                        field: 'count',
                        title: '收藏数量'
                    },
                    {
                        field: 'cname',
                        title: '旅游线路分类表id',
                    }, {
                        field: 'rimage',
                        title: '旅游地址风景图',
                        formatter: function (value, row, index) {
                            return "<img src='<%=path%>/file/download?filename=" + value + "' width='100px' height='100px'>";
                        }

                    }, {
                        field: 'sname',
                        title: '所属商家表id',

                    }, {
                        field: 'sourceid',
                        title: '抓取数据的来源id',
                    },

                    {
                        title: "操作",
                        //value daibiaozhi row 代表 数据 index 代表当前下表
                        formatter: function (value, row, index) {
                            var id = row.rid;
                            var result = "";
                            result += "<a href='javascript:toUpdate(" + id + ")' class='btn btn-xs blue' title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
                            result += "<a href='javascript:deleteInfoById(" + id + ")' class='btn btn-xs red' title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
                            result += "<a href='javascript:imggo(" + id + ")' class='btn btn-xs red' title='tupian'><span class='glyphicon glyphicon-remove'></span></a>";
                            return result;
                        }

                    },]

            });

        })

        function deleteInfoById(id) {
            alert(id)
            $.ajax({
                url: "<%=path%>/route/deleteByid",
                data: {id: id},
                dataType: "json",
                type: "post",
                success: function (result) {
                    if (result = true) {
                        alert("删除成功");
                        $("#table").bootstrapTable("refresh");
                    } else {
                        alert("删除失败")
                    }


                },
                error: function (result) {
                    console.log(result);
                    alert("网络异常请刷新");

                }


            })
        };

        function imggo(id) {
            BootstrapDialog.show({
                title: '增加图片',
                message: $('<div></div>').load('<%=path%>/route/addimg?rid=' + id),
                closeable: true,
                buttons: [{
                    label: '取消',
                    action: function (dialog) {
                        dialog.close();
                    }

                }, {
                    label: '确定',
                    action: function (dialog) {
                        alert($("#img_update").serialize());

                        $.ajax({
                            url: "<%=path%>/route/addimginfo",
                            type: "post",
                            dataType: "json",
                            data: $("#img_update").serialize(),
                            success: function (data) {
                                toastr.success("增加成功");
                                $("#table").bootstrapTable("refresh");


                            },
                            error: function (data) {
                                console.log(data);
                                alert("网络异常");
                            }

                        })

                    }
                }
                ]

            })
        }

        function selectInfo() {
            $("#table").bootstrapTable("refresh");
        }


        function piliangshanchu() {
            var ids = [];
            //获取数据
            var rows = $("#table").bootstrapTable("getSelections");
            console.log(rows);
            $(rows).each(function (i, e) {
                ids.push(e.rid);


            })
            if (ids.length <= 0) {
                alert("么有")
                return;
            }
            $.ajax({
                url: "<%=path%>/route/deleteshanchu",
                type: "post",
                dataType: "json",
                data: {ids: ids},

                async: true,
                success: function (result) {
                    toastr.success("删除成功");
                    selectInfo();

                },
                error: function (result) {
                    toastr.error("网络异常")
                    console.log(result);
                }

            })
        }

        function toUpdate(id) {
            alert(id);
            BootstrapDialog.show({
                title: '修改',
                message: $('<div></div>').load('<%=path%>/route/huixuan?rid=' + id),
                closeable: true,
                buttons: [{
                    label: '取消',
                    action: function (dialog) {
                        dialog.close();
                    }

                }, {
                    label: '确定',
                    action: function (dialog) {
                        $.ajax({
                            url: "<%=path%>/route/updateInfo",
                            type: "post",
                            dataType: "json",
                            data: $("#update_add").serialize(),
                            success: function (data) {
                                toastr.success("修改");
                                $("#table").bootstrapTable("refresh");


                            },
                            error: function (data) {
                                console.log(data);
                                alert("网络异常");
                            }

                        })

                    }
                }
                ]

            })
        }

        function insertInto() {
            BootstrapDialog.show({
                title: '增加',
                message: $('<div></div>').load('<%=path%>/route/addInfo'),
                closeable: true,
                buttons: [{
                    label: '取消',
                    action: function (dialog) {
                        dialog.close();
                    }

                }, {
                    label: '确定',
                    action: function (dialog) {
                        $.ajax({
                            url: "<%=path%>/route/insertinto",
                            type: "post",
                            dataType: "json",
                            data: $("#add_form").serialize(),
                            success: function (data) {
                                $("#table").bootstrapTable("refresh");


                            },
                            error: function (data) {
                                console.log(data);
                                alert("网络异常");
                            }

                        })

                    }
                }
                ]

            })
        }

    </script>
</head>
<body>

<div id="for_div">
    <form class="form-inline" role="form">
        <div class="form-group">
            <label class="sr-only" for="rname">地址名称</label>
            <input type="text" class="form-control" id="rname" name="rname" placeholder="请输入名称">
            <select name="rflag" id="rflag">
                <option value="1">上架</option>
                <option value="2">下架</option>
            </select>

        </div>
        <input type="button" class="btn btn-default" onclick="selectInfo()" value="提交">
        <input type="button" class="btn btn-danger" value="批量删除" onclick="piliangshanchu()">
        <input type="button" class="btn btn-default" value="增加" onclick="insertInto()">


    </form>
</div>
<table id="table"></table>
</body>
</html>
